package com.wang.project.utils;

import cn.hutool.core.util.IdUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class CommonUtils {

    private final static String refreshKeyOrderPrefix = "AS";
    private final static String addInterfaceNumOrderPrefix = "AI";

    /**
     * 获取zfbinfo.properties文件里的值
     *
     * @param name key
     * @return
     * @throws Exception
     */
    public String getZFBinfoValue(String name) throws Exception {
        Properties props = new Properties();
        props.load(getClass().getResourceAsStream("/zfbinfo.properties"));
        return props.getProperty(name);
    }


    /**
     * 根据支付类型加上糊涂生成的uuid组成唯一订单编号
     *
     * @return
     */
    public static String getAlipayOutTradeNo(String payType) {
        String simpleUUID = payType + IdUtil.simpleUUID();
        return simpleUUID;
    }

    /**
     * 生成六位随机验证码
     *
     * @return
     */
    public static String getVerityCode() {
        Random random = new Random();
        StringBuilder sb = new StringBuilder();
        final int length = 6;
        for (int i = 0; i < length; i++) {
            int digit = random.nextInt(10); // 生成 0-9 之间的随机数
            sb.append(digit);
        }
        return sb.toString();
    }

    /**
     * 校验邮箱是否合法
     *
     * @param email
     * @return
     */
    public static Boolean isValidEmail(String email) {
        // 定义邮箱格式的正则表达式
        String regex = "^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+$";

        // 编译正则表达式
        Pattern pattern = Pattern.compile(regex);

        // 创建匹配器
        Matcher matcher = pattern.matcher(email);

        // 执行匹配并返回结果
        return matcher.matches();
    }
}